﻿using Artech.Common;
using Artech.Core.Caching;
using Artech.Core.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

namespace Artech.Core.Resources.Configuration
{
    public class DbResourceProviderData : ResourceProviderDataBase, IDbProviderData 
    {
        public DbResourceProviderData() { }
        public DbResourceProviderData(Type type)
            : base(null, type) { }
        public DbResourceProviderData(string name, Type type)
            : base(name, type) { }

        protected override Expression<Func<IResourceProvider>> CreateProvider(IConfigurationSource configurationSource)
        {
            return ()=> new DbResourceProvider(this.DatabaseName, this.ApplicationName,this.CacheEnabled,this.CacheGranularity,this.CacheStoreAccessor);
        }

        [ConfigurationProperty(Constants.ConfigurationProperties.ApplicationName, IsRequired = true)]
        public string ApplicationName
        {
            get { return (string)base[Constants.ConfigurationProperties.ApplicationName]; }
            set { base[Constants.ConfigurationProperties.ApplicationName] = value; }
        }

        [ConfigurationProperty(Constants.ConfigurationProperties.DatabaseName, IsRequired = true)]
        public string DatabaseName
        {
            get { return (string)base[Constants.ConfigurationProperties.DatabaseName]; }
            set { base[Constants.ConfigurationProperties.DatabaseName] = value; }
        }
    }
}
